package com.dai.zhenfujin.visitingcard.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.dai.zhenfujin.R;
import com.dai.zhenfujin.visitingcard.app.PersonalDetailsActivity;
import com.dai.zhenfujin.visitingcard.bean.VisitingCardBean;

import java.util.List;

public class VisitingCardAdapter extends BaseAdapter{

    private Context context;
    private List<VisitingCardBean> visitingCardBeanList;


    public VisitingCardAdapter(Context context,List<VisitingCardBean> visitingCardBean){
        this.context = context;
        this.visitingCardBeanList = visitingCardBean;
    }

    @Override
    public int getCount() {
        return visitingCardBeanList.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }


    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
         VIewHolder holder;
        if(convertView == null){
            holder = new VIewHolder();
            convertView = View.inflate(context,R.layout.visitingcard_item,null);
            holder.tvName = (TextView)convertView.findViewById(R.id.item_name);//姓名
            holder.tvPosition = (TextView)convertView.findViewById(R.id.item_position);//职位
            holder.tvDistance = (TextView)convertView.findViewById(R.id.item_distance);//距离
            holder.tvBloc = (TextView)convertView.findViewById(R.id.item_bloc);//集团
            holder.tvCompany = (TextView)convertView.findViewById(R.id.item_company);//公司
            holder.tvPrice = (TextView)convertView.findViewById(R.id.item_price);//价格
            holder.tvResidence = (TextView)convertView.findViewById(R.id.item_residence);//住宅
            holder.tvSite = (TextView)convertView.findViewById(R.id.item_site);//地址
            holder.ivOne = (ImageView) convertView.findViewById(R.id.item_imageview_one);//人的图片
            holder.ivTwo = (ImageView)convertView.findViewById(R.id.item_imageview_two);//房子的图片

            convertView.setTag(holder);
        }else {
           holder= (VIewHolder) convertView.getTag();
        }


        VisitingCardBean visitingCardBean = visitingCardBeanList.get(position);
        holder.tvName.setText(visitingCardBean.getName());
        holder.tvPosition .setText(visitingCardBean.getPosition());
        holder.tvDistance.setText(visitingCardBean.getDistance());
        holder.tvBloc.setText(visitingCardBean.getBloc());
        holder.tvCompany.setText(visitingCardBean.getCompany());
        holder.tvPrice.setText(visitingCardBean.getPrice());
        holder.tvResidence.setText(visitingCardBean.getResidence());
        holder.tvSite.setText(visitingCardBean.getSite());



        holder.ivOne.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context,PersonalDetailsActivity.class);
                context.startActivity(intent);

            }
        });

        return convertView;
    }


    private class VIewHolder{

        private TextView tvName,tvPosition,tvDistance,tvBloc,tvCompany,tvPrice,tvResidence,tvSite;
        private ImageView ivOne,ivTwo;
    }
}
